package com.ruoyi.logistics.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.logistics.domain.Center;
import com.ruoyi.logistics.service.ICenterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物流中心Controller
 *

 * @date 2023-07-23
 */
@RestController
@RequestMapping("/center")
public class CenterController extends BaseController
{
    @Autowired
    private ICenterService centerService;

    /**
     * 查询物流中心列表
     */
    @RequiresPermissions("logistics:center:list")
    @GetMapping("/list")
    public TableDataInfo list(Center center)
    {
        startPage();
        List<Center> list = centerService.selectCenterList(center);
        return getDataTable(list);
    }

    /**
     * 导出物流中心列表
     */
    @RequiresPermissions("logistics:center:export")
    @Log(title = "物流中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Center center)
    {
        List<Center> list = centerService.selectCenterList(center);
        ExcelUtil<Center> util = new ExcelUtil<Center>(Center.class);
        util.exportExcel(response, list, "物流中心数据");
    }

    /**
     * 获取物流中心详细信息
     */
    @RequiresPermissions("logistics:center:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(centerService.selectCenterById(id));
    }

    /**
     * 获取完整物流中心详细信息
     */
    @RequiresPermissions("logistics:center:query")
    @GetMapping(value = "/Explicit/{id}")
    public AjaxResult getExplicitInfo(@PathVariable("id") Long id)
    {
        return success(centerService.selectExplicitCenterById(id));
    }

    /**
     * 新增物流中心
     */
    @RequiresPermissions("logistics:center:add")
    @Log(title = "物流中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Center center)
    {
        return toAjax(centerService.insertCenter(center));
    }

    /**
     * 修改物流中心
     */
    @RequiresPermissions("logistics:center:edit")
    @Log(title = "物流中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Center center)
    {
        return toAjax(centerService.updateCenter(center));
    }

    /**
     * 删除物流中心
     */
    @RequiresPermissions("logistics:center:remove")
    @Log(title = "物流中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(centerService.deleteCenterByIds(ids));
    }
}
